<?php

namespace App\Api\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;


class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    /**
     * 设置用户登录认证使用 Guard, 详情见: config/auth.php
     *
     * @var string
     */
    protected $guard = 'administor';

    // protected $Api_url='http://192.168.0.117';
//    http://192.168.0.117
//    https://test.ibeibeili.com
//    https://mobile.ibeibeili.com
    /**
     * 根据控制器 action 生成重定向   
     *
     * @param  string  $action
     * @param  array   $parameters
     * @param  int     $status
     * @param  array   $headers
     * @return \Illuminate\Http\RedirectResponse
     */
    protected function redirectAction($action, $parameters = [], $status = 302, $headers = [])
    {
        $namespace = '\App\Api\Http\Controllers';

        return redirect()->action($namespace.'\\'.$action, $parameters, $status, $headers);
    }

    /**
     * 当前用户
     *
     * @return App\Admin\User
     */
    protected function currentUser()
    {
        return \Auth::guard($this->guard)->user();
    }
    /*
     * 对接SID
     */
    public function __construct(Request $request){
    }
    /*
     * 获取当前域名
     */
    function getNowUrl(){
       return 'https://'.$_SERVER['HTTP_HOST'];
//     return  'http://192.168.0.117';

    }
    /*
     *统一出口
     */
    function my_jsonp($callback,$data=[],$m_status=200,$message=null){
        $SID=session()->getId();
        switch($m_status){
//VII
//正确码(不提示)(200)
            case 200:
                $message='';
                break;

//正确提示(点击继续前往页面)(900-999)
            case 900:
                $message='注册成功';
                break;
            case 901:
                $message='手机认证成功';
                break;
            case 902:
                $message='实名认证成功';
                break;
            case 903:
                $message='银行卡绑定成功';
                break;
            case 904:
                $message='银行卡解绑成功';
                break;
            case 905:
                $message='邮箱验证发送成功,验证30分钟内有效';
                break;
            case 906:
                $message='修改密码成功';
                break;

//错误提示(点击停留在本页面)(600-899)
            case 600:
                $message=$message;
                break;
            case 899:
                $message='输入信息不符合规则,'.$message;
                break;
        //验证码错误
            case 601:
                $message='验证码错误';
                break;
            case 602:
                $message='验证码已失效';
                break;

            //sinna手机验证码
            case 603:
                $message='验证码发送失败,'.$message;
                break;
            case 604:
                $message='请输入验证码';
                break;
            case 606:
                $message='请先发送验证码';
                break;
            //bbl手机验证码
            case 605:
                $message='验证码发送失败';
                break;

        //注册错误
            case 610:
                $message='该手机号已注册';
                break;
            case 611:
                $message='推荐人不存在';
                break;
        //登录错误
            case 620:
                $message='用户不存在';
                break;
            case 621:
                $message=$message;//密码输入错误N次,您还有5-N次机会
                break;
            case 629:
                $message=$message;
                break;
        //密码修改失败
            case 630:
                $message='密码修改失败';

        //认证&绑定错误
            //实名认证
            case 710:
                $message='认证失败,该用户已实名认证';
                break;
            case 711:
                $message='认证失败,请输入正确的身份证号码';
                break;
            case 712:
                $message='认证失败,该实名已被认证';
                break;
            //手机&邮箱认证
            case 721:
                $message='认证失败,'.$message;
                break;
            case 722:
                $message='认证失败,该邮箱已认证';
                break;
            case 723:
                $message='认证失败,该邮箱认证链接已失效';
                break;
            case 724:
                $message='认证失败,原邮箱不正确';
                break;
            case 725:
                $message='认证失败,邮箱验证码发送失败';
                break;
            //绑定银行卡错误
            case 730:
                $message='银行卡绑定失败,'.$message;
                break;
            case 731:
                $message='银行卡号与银行不匹配';
                break;
            case 732:
                $message='解除银行卡绑定失败,'.$message;
                break;
            //购标金额错误
            case 801:
                $message='金额不可大于项目可投金额';
                break;
            case 802:
                $message='金额不可小于项目起投金额';
                break;
//            case 803:
//                $message='金额不可大于用户可用余额';
//                break;
            case 804:
                $message='金额需为项目可投金额倍数';
                break;
            case 805:
                $message='有红包已被使用，请重新选择';
                break;

//友情提示(点击跳转页面)(400-499)
            case 400:
                $data=null;
                $message='请先登录';
                break;
            case 411:
                $message='请先实名认证';
                break;
            case 412:
                $message='请先绑定手机';
                break;
            case 413:
                $message='请先绑定银行卡';
                break;
            case 414:
                $message='余额不足,请先充值';
                break;

            default:
                $message='系统错误,请稍后再试';
                break;
        }
//        $log=json_encode(compact('data','SID','m_status','message'));
//        \Log::info('OUT'.$log);
        return response()->jsonp($callback,compact('data','SID','m_status','message'));
    }
}
